package com.hlkj.baojin.jwt;

import com.hlkj.baojin.dao.IUserDao;
import com.hlkj.baojin.entity.User;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;

/**
 * token 验证 及日志记录
 * lzx
 */
@Document
public class TokenExpiration implements Serializable {


    @Id
    private String id;
    /**
     * tokenNAme
     */
    private String tokenId;
    /**
     * tokenNAme
     */
    private String subjectName;
    /**
     * token是否可用
     */
    private Boolean tokenUse = Boolean.TRUE;
    /**
     * 公司id
     */
    private String deptId;
    /**
     * 登录ip
     */
    private String ip;

    /**
     * 创建时间
     */
    private Long createTime;
    /**
     * 是否删除
     */
    private Boolean delete = Boolean.FALSE;

    /**
     * 类型 1 登录刷新token  2.接口刷新token
     */
    private Integer type;


    public TokenExpiration(IUserDao userDAO, String sub, String tokenId) {
        User user = userDAO.findByUsername(sub);
        this.deptId = user.getDeptId();
        this.tokenId = tokenId;
        this.createTime = System.currentTimeMillis();
        //   接口刷新token
        this.type = 2;
    }

    public TokenExpiration(IUserDao userDAO, String subjectName, String tokenId, String ip) {
        User user = userDAO.findByUsername(subjectName);
        this.deptId = user.getDeptId();
        this.subjectName = subjectName;
        this.tokenId = tokenId;
        this.ip = ip;
        this.createTime = System.currentTimeMillis();
        //1 登录刷新token
        this.type = 1;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getTokenId() {
        return tokenId;
    }

    public void setTokenId(String tokenId) {
        this.tokenId = tokenId;
    }


    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public Boolean getTokenUse() {
        return tokenUse;
    }

    public void setTokenUse(Boolean tokenUse) {
        this.tokenUse = tokenUse;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Boolean getDelete() {
        return delete;
    }

    public void setDelete(Boolean delete) {
        this.delete = delete;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSubjectName() {
        return subjectName;
    }

    public void setSubjectName(String subjectName) {
        this.subjectName = subjectName;
    }


}
